import java.util.LinkedList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:二叉树力扣
 * User: LianBao
 * Date: 2024-04-10
 * Time: 21:50
 */

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;

    TreeNode() {
    }

    TreeNode(int val) {
        this.val = val;
    }

    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}

public class Test {
    List<Integer> list1 = new LinkedList<>();
    List<Integer> list2 = new LinkedList<>();
    List<Integer> list3 = new LinkedList<>();
    //中序遍历
    public List<Integer> inorderTraversal(TreeNode root) {
        if (root == null) {
            return list1;
        }
        inorderTraversal(root.left);
        list1.add(root.val);
        inorderTraversal(root.right);
        return list1;
    }

    //后序遍历
    public List<Integer> postorderTraversal(TreeNode root) {
        if(root==null) {
            return list2;
        }
        postorderTraversal(root.left);
        postorderTraversal(root.right);
        list2.add(root.val);
        return list2;
    }
    //前序遍历
    public List<Integer> preorderTraversal(TreeNode root) {
        if(root==null) {
            return list3;
        }
        list3.add(root.val);
        preorderTraversal(root.left);
        preorderTraversal(root.right);
        return list3;
    }
}
